<?php
class MPayAccount extends MY_Model {

    protected $table = 'pay_account';

    function __construct() {
        parent::__construct();
    }

    public function getList($limit, $sort=false){
        $this->db->select( '*');
        $this->db->distinct();
        $this->db->from($this->table);
        $this->db->limit($limit['limit'],$limit['offset']);
        $this->formfilter->doFilter();
        if($sort){
            $this->db->order_by('sort', 'asc');
        }else{
            $this->db->order_by('id', 'desc');
        }
        $query = $this->db->get();
        return $query->result();
    }
    public function getCount(){
        $this->db->select('count(distinct id) as num');
        $this->db->from($this->table);
        $this->formfilter->doFilter();
        $tmp = $this->db->get()->result();
        return (int)$tmp[0]->num;
    }

    public function getById($id){
        $query = $this->db->where('id',$id)->get($this->table);
        return $query->row();
    }

    /**
     * 得到所有可用的银行付款账号
     */
    public function getAllAvailableAccount(){
        $this->db->select('id,name,account');
        $this->db->from($this->table);
        $this->db->where('status',1);
        $queryResult = $this->db->get()->result();
        $kvArr = array();
        foreach ($queryResult as $k=>$v){
            $kvArr[$v->id] = $v->name.'-'.$v->account;
        }
        return $kvArr;

    }

}
